package com.yhsimon.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @author： YHSimon
 * @date： 2021-10-12 14:45
 */
public class OutPutImpl {
    //学院集合
    List<College> collegeList;

    public OutPutImpl(List<College> collegeList){
        this.collegeList=collegeList;
    }

    // 遍历所有学院，然后调用printDepartment 输出各个学院的系
    public void printCollege(){
        //从collegeList 取出所有学院 Java的list已经实现Iterator
        Iterator<College> iterator = collegeList.iterator();
        while (iterator.hasNext()){
            College college = iterator.next();
            System.out.println("======"+college.getName()+"======");
            printDepartment(college.createIterator());
        }
    }

    // 输出 学院 系
    public void printDepartment(Iterator iterator){
        while(iterator.hasNext()){
            Department d = (Department) iterator.next();
            System.out.println(d.getName());
        }
    }
}
